package com.lefeng.cockpit.admin.api.v1.datax;


import com.didiglobal.logi.security.common.Result;
import com.lefeng.cockpit.common.bean.dto.dataxjson.DataXJsonBuildDto;
import com.lefeng.cockpit.common.bean.dto.job.TriggerJobDto;
import com.lefeng.cockpit.datax.core.biz.model.ReturnT;
import com.lefeng.cockpit.datax.service.JobService;
import com.lefeng.cockpit.datax.thread.JobTriggerPoolHelper;
import com.lefeng.cockpit.datax.trigger.TriggerTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * index controller
 *
 * @author weifw
 */
@Api(tags = "datax-任务配置接口")
@RestController
@RequestMapping("/api/job")
public class JobInfoController {

    @Resource
    private JobService jobService;


    @PostMapping(value = "/trigger")
    @ApiOperation("触发任务")
    public ReturnT<String> triggerJob(@RequestBody @Validated TriggerJobDto dto) {
        JobTriggerPoolHelper.trigger(dto.getJobId(), TriggerTypeEnum.MANUAL, -1, null, dto.getExecutorParam());
        return ReturnT.SUCCESS;
    }

    @PostMapping("/buildJson")
    @ApiOperation("JSON构建")
    public Result<String> buildJobJson(@RequestBody @Validated DataXJsonBuildDto dto) {
        return Result.buildSucc(jobService.buildJobJson(dto));
    }

}
